package com.example.lixiaomao.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.concurrent.Executors;

public class MainActivity extends AppCompatActivity {
    private RecyclerView mRecycler;
    private LocalAdapter mLocalAapter;
    private RecyclerView.LayoutManager mLayoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mRecycler = findViewById(R.id.list_rv);
        mLocalAapter = new LocalAdapter();
        mLayoutManager = new GridLayoutManager(this,3);
        mRecycler.setAdapter(mLocalAapter);
        mRecycler.setLayoutManager(mLayoutManager);


        Executors.newCachedThreadPool().submit(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                    final ArrayList<ItemBean> serverData = new ArrayList<>();
                    for (int i = 0; i < 100; i++) {
                        serverData.add(new ItemBean("title" + i, "content" + i));
                    }
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mLocalAapter.setmDataset(serverData);
                            mLocalAapter.notifyDataSetChanged();
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
    }




}
